<?php

use App\Site\Contract\MenuServiceInterface;
use App\Site\Contract\SiteServiceInterface;
use Deepwell\HyperfUid\Contract\WorkerIdAssignerServiceInterface;
use function Hyperf\Support\value;

return [
    'consumers' => value(function () {
        $services = [
            'WorkerIdAssignerService' => WorkerIdAssignerServiceInterface::class,
            'SiteService' => SiteServiceInterface::class,
            'MenuService' => MenuServiceInterface::class,
        ];
        $consumers = [];
        foreach ($services as $name => $service) {
            $consumers[] = array_merge([
                'name' => $name,
                'service' => $service,
                'id' => $service,
            ], [
                'protocol' => Hyperf\RpcMultiplex\Constant::PROTOCOL_DEFAULT,
                'load_balancer' => 'random',
                'nodes' => [
                    ['host' => env('RPC_SERVICE_HOST'), 'port' => (int)env('RPC_SERVICE_PORT')],
                ],
                'options' => [
                    'connect_timeout' => 5.0,
                    'recv_timeout' => 5.0,
                    'settings' => [
                        // 包体最大值，若小于 Server 返回的数据大小，则会抛出异常，故尽量控制包体大小
                        'package_max_length' => 1024 * 1024 * 2,
                    ],
                    // 重试次数，默认值为 2
                    'retry_count' => 2,
                    // 重试间隔，毫秒
                    'retry_interval' => 100,
                    // 多路复用客户端数量
                    'client_count' => 4,
                    // 心跳间隔 非 numeric 表示不开启心跳
                    'heartbeat' => 30,
                ],
            ]);
        }
        return $consumers;
    })
];